<template>
  <div class="dataVisualize-box">
    <div class="card top-box">
      <div class="top-content">
        <el-row :gutter="40">
          <el-col class="mb15" :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
            <div class="item-left sle">
              <span class="left-title">{{
                $t("nearby.Besucheinsgesamt")
              }}</span>
              <div class="img-box">
                <img src="./images/book-sum.png" alt="" />
              </div>
              <span class="left-number"> {{ Math.round(totalOutput) }}</span>
            </div>
          </el-col>
          <el-col class="mb15" :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
            <div class="item-center">
              <div class="gitee-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/add_person.png" alt="" />
                </div>
                <span class="item-value">
                  {{ Math.round(userNumberOutput) }}</span
                >
                <span class="traffic-name sle">{{
                  $t("nearby.Benutzervolumen")
                }}</span>
              </div>
              <div class="gitHub-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/add_team.png" alt="" />
                </div>
                <span class="item-value">
                  {{ Math.round(submitNumberOutput) }}</span
                >
                <span class="traffic-name sle">{{
                  $t("nearby.heutigeEinreichungsvolumen")
                }}</span>
              </div>
              <div class="today-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/today.png" alt="" />
                </div>
                <span class="item-value">
                  {{ Math.round(todayVisitOutput) }}</span
                >
                <span class="traffic-name sle">{{
                  $t("nearby.heutigenBesuche")
                }}</span>
              </div>
              <div class="yesterday-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/book_sum.png" alt="" />
                </div>
                <span class="item-value">
                  {{ Math.round(yesterdayVisitOutput) }}</span
                >
                <span class="traffic-name sle">{{
                  $t("nearby.gestrigenBesuche")
                }}</span>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col class="mb10">
            <div class="item-right">
              <div class="echarts-title">
                {{ $t("nearby.besuchtenRegionen") }}
              </div>
              <div class="book-echarts">
                <Pie ref="pieRef" />
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <back-top></back-top>
  </div>
</template>

<script setup lang="ts" name="dataVisualize">
import Pie from "./components/pie.vue";
import BackTop from "@/components/BackTop/index.vue";
import { TransitionPresets } from "@vueuse/core";
import { getSummary } from "@/api/other/index";

const pieRef = ref();
const duration = 5000;
// 访问总数
const total = ref(0);
const totalOutput = useTransition(total, {
  duration: duration,
  transition: TransitionPresets.easeOutExpo,
});
// 用户量
const userNumber = ref(0);
const userNumberOutput = useTransition(userNumber, {
  duration: duration,
  transition: TransitionPresets.easeOutExpo,
});
// 今日提交量
const submitNumber = ref(0);
const submitNumberOutput = useTransition(submitNumber, {
  duration: duration,
  transition: TransitionPresets.easeOutExpo,
});
// 今日访问量
const todayVisit = ref(0);
const todayVisitOutput = useTransition(todayVisit, {
  duration: duration,
  transition: TransitionPresets.easeOutExpo,
});
// 昨日访问量
const yesterdayVisit = ref(0);
const yesterdayVisitOutput = useTransition(yesterdayVisit, {
  duration: duration,
  transition: TransitionPresets.easeOutExpo,
});
interface pieDataType {
  value: number;
  name: string;
}
const pieData = ref<pieDataType[]>([]);

function handleQuery() {
  getSummary().then(({ data }) => {
    total.value = data.total;
    userNumber.value = data.userNumber;
    submitNumber.value = data.submitNumber;
    todayVisit.value = data.todayVisit;
    yesterdayVisit.value = data.yesterdayVisit;
    pieData.value = data.proportion;
    pieRef.value.initChart(pieData.value);
  });
}
onMounted(() => {
  handleQuery();
  pieRef.value.initChart(pieData.value);
});
</script>

<style scoped lang="scss">
.dataVisualize-box {
  /* 文字单行省略号 */
  .sle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* custom card */
  .card {
    margin: 12px;
    box-sizing: border-box;
    padding: 10px;
    overflow-x: hidden;
    background-color: var(--el-bg-color);
    border: 1px solid var(--el-border-color-light);
    border-radius: 6px;
    box-shadow: 0 0 12px rgb(0 0 0 / 5%);
    // margin-bottom: -10px;
  }
  .top-box {
    box-sizing: border-box;
    padding: 25px 40px 0;
    .top-title {
      margin-bottom: 10px;
      font-family: DIN;
      font-size: 18px;
      font-weight: bold;
    }
    .top-content {
      margin-top: 10px;

      .item-left {
        box-sizing: border-box;
        height: 100%;
        padding: 40px 0 30px 30px;
        overflow: hidden;
        color: #ffffff;
        background: url("./images/book-bg.png");
        opacity: 0.9;
        background-position: 50%;
        background-size: cover;
        border-radius: 20px;
        .left-title {
          font-family: DIN;
          font-size: 20px;
        }
        .img-box {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 90px;
          height: 90px;
          margin: 40px 0 20px;
          background-color: #ffffff;
          border-radius: 20px;
          box-shadow: 0 10px 20px rgb(0 0 0 / 14%);
          img {
            width: 60px;
            height: 65px;
          }
        }
        .left-number {
          overflow: hidden;
          font-family: DIN;
          font-size: 62px;
        }
      }
      .item-center {
        display: flex;
        flex-wrap: wrap;
        align-content: space-between;
        justify-content: space-between;
        height: 100%;
        .traffic-box {
          box-sizing: border-box;
          display: flex;
          flex-direction: column;
          width: 47%;
          height: 48%;
          padding: 25px;
          border-radius: 30px;
          .traffic-img {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 70px;
            height: 70px;
            margin-bottom: 10px;
            background-color: #ffffff;
            border-radius: 19px;
          }
        }
        img {
          width: 33px;
          height: 33px;
        }
        .item-value {
          margin-bottom: 4px;
          font-family: DIN;
          font-size: 28px;
          font-weight: bold;
          color: #1a1a37;
        }
        .traffic-name {
          overflow: hidden;
          font-family: DIN;
          font-size: 15px;
          color: #1a1a37;
          white-space: nowrap;
        }
        .gitee-traffic {
          background: url("./images/1-bg.png");
          background-color: #e8faea;
          background-size: 100% 100%;
        }
        .gitHub-traffic {
          background: url("./images/2-bg.png");
          background-color: #e7e1fb;
          background-size: 100% 100%;
        }
        .today-traffic {
          background: url("./images/3-bg.png");
          background-color: #fdf3e9;
          background-size: 100% 100%;
        }
        .yesterday-traffic {
          background: url("./images/4-bg.png");
          background-color: #f0f5fb;
          background-size: 100% 100%;
        }
      }
      .item-right {
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 430px;
        border: 1px solid var(--el-border-color);
        border-radius: 25px;
        .echarts-title {
          padding: 15px 20px;
          font-family: DIN;
          font-size: 18px;
          font-weight: bold;
          border-bottom: 1px solid var(--el-border-color);
        }
        .book-echarts {
          flex: 1;
          width: 100%;
        }
      }
    }
  }
  .bottom-box {
    position: relative;
    padding: 20px 0 0;
    .bottom-title {
      position: absolute;
      top: 75px;
      left: 50px;
      font-family: DIN;
      font-size: 18px;
      font-weight: bold;
    }
    .bottom-tabs {
      padding: 0 50px;
    }
    .curve-echarts {
      box-sizing: border-box;
      height: 400px;
      padding: 0 50px;
    }
  }
}
</style>
